﻿@using System;
@using System.Text;
@using System.Linq;
@using System.Web.Mvc;
@using System.Collections;
@using System.Collections.Generic;
@using System.Xml;
@using System.IO;
@using System.Reflection;
@using Lib.core;
@using Lib.helper;
@{
    Layout = null;
}

@helper RenderType(Type t)
{
    if (t.IsGenericType && t.GetGenericArguments().Length > 0)
    {
        var name = t.GetGenericArguments()[0].Name;
        <span>@(t.GetGenericTypeDefinition().Name)(@(name))</span>
    }
    else
    {
        <span>@(t.Name)</span>
    }
}

@{
    var typelist = new List<Type>() { typeof(Hiwjcn.Web.Controllers.AccountController) };

    foreach (var type in typelist)
    {
        var dict = new Dictionary<string, List<MethodInfo>>();

        var controllers = Assembly.GetAssembly(type).GetTypes()
            .Where(x => x.Name.IndexOf("Controller") >= 0).ToList();
        foreach (var con in controllers)
        {
            var list = new List<MethodInfo>();
            var actions = con.GetMethods().Where(x => x.ReturnType == typeof(ActionResult)).ToList();
            list.AddRange(actions);

            dict[con.Name] = list;
        }

        if (ValidateHelper.IsPlumpDict(dict))
        {
            foreach (var key in dict.Keys)
            {
                var list = dict[key];
                foreach (var me in list)
                {
                    <p>/** @@api {post} @(key.Replace("Controller", ""))/@(me.Name)</p>
                    <p>* @@apiName @(me.Name)</p>
                    <p>* @@apiGroup @(key.Replace("Controller", ""))</p>
                    var paramlist = me.GetParameters();
                    foreach (var p in paramlist)
                    {
                        <p>* @@apiParam {@(RenderType(p.ParameterType))} @(p.Name)</p>
                    }
                    <p>* @@apiVersion 1.0</p>
                    <p>*/</p>
                    <p></p>
                }
            }
        }
    }

}
